package report

import java.util.Date;
import user.Petiano 
import user.User 

class Activity {
	
	String nature
	String theme
	String target
	String type
	String description
	String reasons
	String expectedResults
	String actualResults
	String comments
	String partners
	Date startDate
	Date endDate
	int status
	Plan plan
	
	static belongsTo = [User]
	static hasMany = [sponsors:User, months:String]
	
    static constraints = {
		nature(blank:false, nullable:false, size:2..128, matches:"(\\p{L})+(\\s(\\p{L})*)*")
		theme(blank:false, nullable:false, size:2..128, matches:"(\\p{L})+(\\s(\\p{L})*)*")
		type(blank:false, nullable:false, inList:['Ensino', 'Extensão', 'Pesquisa', 'Coletiva'])
		description(nullable:false, blank:false)
		target(nullable:false, blank:false)
		reasons(nullable:false, blank:false)
		expectedResults(nullable:false, blank:false)
		actualResults(nullable:false, blank:false)
		partners(nullable:false, blank:false)
		plan(nullable:true)
		months(blank:false, nullable:false, size:1..12)
		status(blank:false, nullable:false, range:0..3)
		startDate(nullable:false)
		endDate(nullable:false)
    }
	
	def isLate = {
		return (startDate <= it && status == ActivityStatus.NOT_STARTED) || (endDate < it && status == ActivityStatus.ONGOING)
	}
	
	def statusString = {
		return ActivityStatus.toValue(status)
	}
	
	def showName = {
		return nature + ", " + theme
	}
	
}

